#define	_CRT_SECURE_NO_WARNINGS 1 

#include "Heap.h"

void swap(HPDataType* parent, HPDataType* child)
{
	HPDataType tmp = *parent;
	*parent = *child;
	*child = tmp;
}

void AdjustUp(HPDataType* hp, int child)
{
	int parent = (child - 1) / 2;
	while (child > 0)
	{
		if (hp[child] > hp[parent])
		{
			swap(&hp[parent], &hp[child]);
			child = parent;
			parent = (child - 1) / 2;
		}
		else
		{
			break;
		}
	}
}
void AdjustDown(HPDataType* hp, int n, int parent)
{
	int child = parent * 2 + 1;
	while (child < n)
	{
		if (child + 1 < n && hp[child] < hp[child + 1])
		{
			child++;
		}
		if (hp[child] > hp[parent])
		{
			swap(&hp[parent], &hp[child]);
			parent = child;
			child = parent * 2 + 1;
		}
		else
		{
			break;
		}
	}
}
